package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * 每个年级4个班，一共6个年级
 */
public class Test3 {
    public static void main(String[] args) throws ClassNotFoundException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        try (
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true", "root", "root");
        ) {
            Statement statement = conn.createStatement();
//            for(int y=1;y<7;y++) {
//                for(int c=1;c<5;c++) {
//                    String sql = "INSERT INTO class (name) VAlUES ('"+y+"年级"+c+"班')";
//                    int num = statement.executeUpdate(sql);
//                    if (num > 0) {//说明至少影响了表中1条记录
//                        System.out.println("插入成功");
//                    } else {
//                        System.out.println("插入失败");
//                    }
//                }
//            }

            for(int y=1,c=0;y<7;y=++c/4+1) {
                String sql = "INSERT INTO class (name) VAlUES ('"+y+"年级"+(c%4+1)+"班')";
                int num = statement.executeUpdate(sql);
                if (num > 0) {//说明至少影响了表中1条记录
                    System.out.println("插入成功");
                } else {
                    System.out.println("插入失败");
                }
            }


        }catch (Exception e){

        }
    }
}
